var gulp = require('gulp'),
    inject=require('gulp-inject'),
    bowerFiles = require('main-bower-files'),
    angularFilesort = require('gulp-angular-filesort');
var browserSync = require('browser-sync').create();

gulp.task('inject',function () {
  var target = gulp.src('index.html');
  var sources = gulp.src(['app/**/*.js']).pipe(angularFilesort());
  return target.pipe(inject(sources))
    .pipe(gulp.dest('./'));

});
gulp.task('bower-inject',function () {
    var target = gulp.src('index.html');
    return target
        .pipe(inject(gulp.src(bowerFiles(), {read: false}), {name: 'bower'}))
        .pipe(gulp.dest('./'));
});

gulp.task('TASKNAME', function() {
 return  gulp.src('index.html')
  .pipe(inject(gulp.src(bowerFiles(), {read: false}), {name: 'bower'})).pipe(gulp.dest('./'))
});

// 静态服务器
gulp.task('server', function() {
    browserSync.init({
        server: {
            baseDir: "./"
        }
    });
    gulp.watch('bower.json', ['inject']);
    gulp.watch('app/**/*.js', ['inject']);
    gulp.watch("app/**/*.*").on("change", browserSync.reload);
});

gulp.task('default',['bower-inject','inject','server']);

